package com.ly.web.controller.erp;

import javax.annotation.Resource;

import com.ly.common.utils.StringUtils;
import com.ly.heart.domain.dto.ContractSaleOrderDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ly.common.annotation.Log;
import com.ly.common.core.controller.BaseController;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.enums.BusinessType;
import com.ly.heart.domain.ContractSaleEntity;
import com.ly.heart.service.IContractSaleService;

/**
 * 光伏材料/逆变器/组件销售合同Controller
 *
 * @author cxl
 * @date 2024-05-16
 */
@Api ( value = "ContractSale", tags = "光伏材料/逆变器/组件销售合同" )
@RestController
@RequestMapping ( "/heart/ContractSale" )
public class ContractSaleController extends BaseController {

    @Resource
    private IContractSaleService iContractSaleService;

    /**
     * 查询光伏材料/逆变器/组件销售合同列表
     */
    @ApiOperation ( "查询光伏材料/逆变器/组件销售合同列表" )
    @PreAuthorize ( "@ss.hasPermi('heart:ContractSale:list')" )
    @GetMapping ( "/list" )
    public AjaxResult list ( ContractSaleEntity contractSaleEntity ) {
        AjaxResult ajaxResult = iContractSaleService.selectContractSaleEntityList ( contractSaleEntity );
        return ajaxResult;
    }

    /**
     * 获取光伏材料/逆变器/组件销售合同详细信息
     */
    @ApiOperation ( "获取光伏材料/逆变器/组件销售合同详细信息" )
    @PreAuthorize ( "@ss.hasPermi('heart:ContractSale:query')" )
    @GetMapping ( value = "/{id}" )
    public AjaxResult getInfo ( @PathVariable ( "id" ) String id ) {
        return AjaxResult.success ( iContractSaleService.selectContractSaleEntityById ( id ) );
    }

    /**
     * 新增光伏材料/逆变器/组件销售合同
     */
    @ApiOperation ( "暂存光伏材料/逆变器/组件销售合同" )
    @PreAuthorize ( "@ss.hasPermi('heart:ContractSale:add')" )
    @Log ( title = "暂存光伏材料/逆变器/组件销售合同", businessType = BusinessType.INSERT )
    @PostMapping ( "draft" )
    public AjaxResult draft ( @RequestBody ContractSaleOrderDto contractSaleOrderDto ) {
        //判断如果有id则进行修改
        ContractSaleEntity contractSaleEntity = contractSaleOrderDto.getContractSaleEntity ();
        AjaxResult result = null;
        if ( StringUtils.isNotBlank ( contractSaleEntity.getId () ) ) {
            //修改
            result = iContractSaleService.updateContractSaleEntity ( contractSaleOrderDto );
        } else {
            result = iContractSaleService.draft ( contractSaleOrderDto );
        }
        return result;
    }

    /**
     * 新增光伏材料/逆变器/组件销售合同
     */
    @ApiOperation ( "提交光伏材料/逆变器/组件销售合同" )
    @PreAuthorize ( "@ss.hasPermi('heart:ContractSale:add')" )
    @Log ( title = "提交光伏材料/逆变器/组件销售合同", businessType = BusinessType.INSERT )
    @PostMapping ( "submit" )
    public AjaxResult submit ( @RequestBody ContractSaleEntity contractSaleEntity ) {
        return iContractSaleService.submit ( contractSaleEntity );
    }

    /**
     * 修改光伏材料/逆变器/组件销售合同
     */
    @ApiOperation ( "修改光伏材料/逆变器/组件销售合同" )
    @PreAuthorize ( "@ss.hasPermi('heart:ContractSale:edit')" )
    @Log ( title = "光伏材料/逆变器/组件销售合同", businessType = BusinessType.UPDATE )
    @PutMapping
    public AjaxResult edit ( @RequestBody ContractSaleOrderDto contractSaleOrderDto ) {
        return iContractSaleService.updateContractSaleEntity ( contractSaleOrderDto );
    }

    /**
     * 删除光伏材料/逆变器/组件销售合同
     */
    @ApiOperation ( "删除光伏材料/逆变器/组件销售合同" )
    @PreAuthorize ( "@ss.hasPermi('heart:ContractSale:remove')" )
    @Log ( title = "光伏材料/逆变器/组件销售合同", businessType = BusinessType.DELETE )
    @DeleteMapping ( "/{ids}" )
    public AjaxResult remove ( @PathVariable String[] ids ) {
        return iContractSaleService.deleteContractSaleEntityByIds ( ids );
    }

    @Log ( title = "新增销售订单界面，通过选销售合同单据时，查询销售合同物料明细列表" )
    @ApiOperation ( "新增销售订单界面，通过选销售合同单据时，查询销售合同物料明细列表" )
    @GetMapping ( "/queryMaterialList" )
    public AjaxResult queryMaterial ( ContractSaleEntity contractSaleEntity ) {
        return iContractSaleService.queryMaterial ( contractSaleEntity );
    }

    @PreAuthorize ( "@ss.hasPermi('heart:ContractSale:close')" )
    @ApiOperation ( "关闭/反关闭销售合同" )
    @Log ( title = "光伏材料/逆变器/组件销售合同", businessType = BusinessType.DELETE )
    @RequestMapping ( "close" )
    public AjaxResult close ( String id ) {
        return iContractSaleService.close ( id );
    }

    @ApiOperation ( "作废销售合同" )
    @Log ( title = "作废销售合同", businessType = BusinessType.DELETE )
    @RequestMapping ( "cancel" )
    public AjaxResult cancel ( String id ) {
        return iContractSaleService.cancel ( id );
    }

}
